package com.superteam.zzl.Des;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2016/12/15.
 */
public class RecommHeadPager1Adapter extends PagerAdapter {
    private Context context;
    private List<String>list;//dizhi jihe
    private List<View> views;

    public RecommHeadPager1Adapter(Context context, List<String> list) {

        this.context = context;
        this.list = list;
        views=new ArrayList<>();
    }


    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {

        final ImageView imageView=new ImageView(context);
      imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        final String imgpath=list.get(position);

        new BitMapAsyncTask(context, new BitMapAsyncTask.CallBack() {
            @Override
            public void sendBitMap(String url, Bitmap bitmap) {
                if (url.equals(imgpath)) {
                    imageView.setImageBitmap(bitmap);
                }
            }
        }).execute(list.get(position));
        views.add(imageView);

        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(views.get(position));
    }
}
